using System;
using System.IO;
using System.Collections.Generic;
using System.Text;

namespace Weazel.Toad.Application.Controls
{
  class ConsoleOutputTextBoxWriter : TextWriter
  {
    public ConsoleOutputControl control;

    public ConsoleOutputTextBoxWriter(ConsoleOutputControl control)
    {
      this.control = control;
      writechardlg = new wdlg(wdlgImpl);
    }

    private delegate void wdlg(char c);
    private wdlg writechardlg;

    private void wdlgImpl(char c)
    {
      control.Append(c);
    }

    public override void Write(char value)
    {
      control.Invoke(writechardlg, new object[] { value });
    }

    public override Encoding Encoding
    {
      get { throw new Exception("The method or operation is not implemented."); }
    }
  }
}
